/*
 * @Author: folusGan 245942153@qq.com
 * @Date: 2024-07-02 11:23:57
 * @LastEditors: folusGan 245942153@qq.com
 * @LastEditTime: 2024-07-09 13:58:59
 * @Description:
 */
const chalk = require('chalk')
export function getUrlArg(name) {
  const reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)')
  const r = window.location.search.substr(1).match(reg)
  if (r != null) return unescape(r[2])
  return null
}

export function changeURLArg(url, arg, arg_val) {
  const pattern = arg + '=([^&]*)'
  const replaceText = arg + '=' + arg_val
  if (url.match(pattern)) {
    var tmp = '/(' + arg + '=)([^&]*)/gi'
    tmp = url.replace(eval(tmp), replaceText)
    return tmp
  } else {
    if (url.match('[?]')) {
      return url + '&' + replaceText
    } else {
      return url + '?' + replaceText
    }
  }
}
// 打印版本、环境、构建时间等信息

const renderClg = function (e) {
  const t = e.title
  const r = e.content
  const n = e.backgroundColor
  const a = [
    '%c '.concat(t, ' %c ').concat(r, ' '),
    'padding: 1px; border-radius: 3px 0 0 3px; color: #fff; background: '.concat(
      '#686060',
      ';'
    ),
    'padding: 1px; border-radius: 0 3px 3px 0; color: #fff; background:  '.concat(
      n,
      ';'
    ),
  ]
  return (
    function () {
      let e
      window.console &&
        typeof window.console.log === 'function' &&
        (e = console).log.apply(e, arguments)
    }.apply(undefined, a),
    a
  )
}
const build_info = [
  {
    title: 'Environment',
    content: process.env.VUE_APP_ENV || 'development', //
    backgroundColor: '#1475BC',
  },
  {
    title: 'Platform',
    content: process.env.PLATFORM || 'web',
    backgroundColor: '#1475BC',
  },
  {
    title: 'Version',
    content: process.env.VERSION || '1.0.0', //
    backgroundColor: '#1475BC',
  },
  {
    title: 'build Date',
    content: process.env.BUILD_AT || '2024-07-03 10:13:34',
    backgroundColor: '#1475BC',
  },
]
export function printBuildInfo() {
  console.log(process.env, 'process.env')
  build_info.forEach((item) => {
    const { title, content, backgroundColor } = item
    return renderClg({
      title,
      content,
      backgroundColor,
    })
  })
}
